<?php
namespace small\model\db;

class SphinxMysql
{
    /** @type object */
    public static $sphinx = null;

    /** @type object */
    public $mysql = null;

    /**
     * 不允许构造函数
     */
    private function __construct()
    {
        
    }

    public static function init()
    {
        if (!self::$sphinx)
        {
            self::$sphinx = new self();
        }

        return self::$sphinx;
    }

    /**
     *
     */
    private function connect()
    {

        if (!$this->mysql) 
        {
            $this->mysql = @mysql_connect("127.0.0.1:9306", '', '');

            // $this->mysql->query('SET NAMES UTF8');
        }
    }

    /**
     *
     */
    public function query($iSql)
    {
        $this->connect();
        return $this->mysql->query($iSql);
    }

    /**
     *
     */
    public function findOne($iSql)
    {
        $this->connect();
        $r = mysql_query($iSql, $this->mysql);
        $result = array();

        while ($s = mysql_fetch_assoc($r)) {
            $result = $s;
            break;
        }

        return $result;
    }

    /**
     * 
     */
    public function findAll($iSql)
    {
        $this->connect();
        $r = mysql_query($iSql, $this->mysql);
        $result = array();

        while ($s = mysql_fetch_assoc($r)) {
            $result[] = $s;
        }

        return $result;
    }

    /**
     *
     */
    public function insert()
    {  
        $this->connect();
        $sql = "INSERT INTO demo(id,u_id,name,love,username,dex,lovetwo,email,create_time) values('19','19','fangfang','ai','fangfang',0,'ai','a@sian.com',0)";
        return mysql_query($sql, $this->mysql);
    }
}
?>